package com.ang.future.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author ssang
 * @date 2023-03-04 8:21
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ExecutorService threadPoolExecutor(){
        ExecutorService myExecutor = new ThreadPoolExecutor(4, 10,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>(10),//阻塞队列，保存操作请求线程
            new MyThreadFactory(),//创建线程的工厂类
            new ThreadPoolExecutor.CallerRunsPolicy());

        return myExecutor;
    }
}
